package demo.java.parallelprogram.future;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * 并行程序开发和优化
 * @author songfeifei
 *
 */
public class Parallelprogram {
	
	
	/**
	 * 
	 */
	public void future(){
		FutureTask<String> future=new FutureTask<>(new RealData("a"));
		ExecutorService executor=Executors.newFixedThreadPool(1);
		executor.submit(future);
		System.out.println("请求完毕");
		//执行其他业务逻辑start
		
		
		//执行其他业务逻辑end
		try {
			System.out.println("数据="+future.get());
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
		System.out.println("===");
		
	}
	
//	public void future(){
//		Client client=new Client();
//		Data data=client.request("name");
//		System.out.println("请求完毕");
//		try {
//			Thread.sleep(2000);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
//		
//		System.out.println(data.getResult());
//	}
}
